<template>
	<view style="padding: 32upx 28upx; ">
		<view class="item" v-for="(item,key) in shops" :key="key">
			<view class="item-head">
				<image src="../../../static/shop.png" mode="" style="width: 32upx;height: 31upx;margin-right: 10upx;"></image>
				<view class="shop-name">
					{{item.name}}
				</view>
				<view class="shop-distance">
					{{item.distance}}km
				</view>
			</view>
			<view class="shop-address">
				{{item.address}}
			</view>
			<view class="shop-time">
				营业时间:{{item.work_time}}
			</view>
			<view class="item-bottom">
				<image src="../../../static/location-green.png" style="width: 40upx;height: 44upx;" mode="" @click="viewLocation(key)"></image>
				<image src="../../../static/phonecall.png" style="width: 46upx;height: 46upx;margin:0 70upx" mode="" @click="phoneCall(key)"></image>
				<view class="choose-btn" @click="chooseShop(key)">选择该店</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shops:[],
			};
		},
		onLoad:function(){
			this.getLocation();
		},
		methods:{
			chooseShop:function(index){
				uni.setStorageSync("selectedShop",this.shops[index]);
				uni.navigateBack({
					
				})
			},
			viewLocation:function(index){
				
				uni.openLocation({
					latitude:parseFloat(this.shops[index].latitude),
					longitude:parseFloat(this.shops[index].longitude),
				})
			},
			phoneCall:function(index){
				uni.makePhoneCall({
					phoneNumber:this.shops[index].phone,
				})
			},
			getLocation:function(){
				uni.showLoading({
					title:"正在获取推荐门店"
				});
				var that=this;
				uni.getLocation({
					type:"gcj02",
					complete:function(e){
						uni.hideLoading();
						that.getRecommendShop(e);
					},
					fail:function(){
						uni.hideLoading();
						uni.showModal({
							title:"位置信息获取失败",
							content:"请手动选择位置",
							confirmText:"手动选择",
							success:function(e){
								if(e.confirm){
									uni.chooseLocation({
										success:function(e){
											that.getRecommendShop(e);
										}
									})
								}
							}
						})
					}
				})
			},
			getRecommendShop:function(location){
				var that=this;
				that.ajax("/shop/nearby/",{
					"latitude":location.latitude,
					"longitude":location.longitude,
					"count":10,
				},function(res){
					that.shops=res.data.data;
				});
			},
		}
	}
</script>

<style>
	.item{
		padding: 28upx;
		background: #ffffff;
		margin-bottom: 20upx;
		box-shadow:0upx 2upx 20upx 0upx rgba(43,159,133,0.14);
		border-radius:12upx;
	}
	.item-head{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.shop-name{
		flex: 1;
		color: #4B4B4B;
		font-size: 28upx;
	}
	.shop-distance{
		color:#8B8B8B;
		font-size:28upx ;
	}
	.shop-address{
		font-size: 26upx;
		color: #4B4B4B;
		padding: 20upx 0;
	}
	.shop-time{
		font-size: 26upx;
		color: #4B4B4B;
		padding: 20upx 0;
	}
	.item-bottom{
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
	}
	.choose-btn{
		background: #45AA8C;
		color: #ffffff;
		font-size: 24upx;
		border-radius: 8upx;
		width: 180upx;
		text-align: center;
		line-height: 60upx;
	}
</style>
